home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Morphos / GCC / ppc-amigaos / include / mgl / context.h < prev    next >
C/C++ Source or Header  |  2000-01-22  |  7KB  |  263 lines

  1. /*
  2.  * $Id: context.h,v 1.5 2000/01/16 20:47:05 hfrieden Exp $
  3.  *
  4.  * $Author: hfrieden $
  5.  *
  6.  * $Date: 2000/01/16 20:47:05 $
  7.  * $Revision: 1.5 $
  8.  *
  9.  * (C) 1999 by Hyperion Software
  10.  * All rights reserved
  11.  *
  12.  * This file is part of the MiniGL library project
  13.  * See the file Licence.txt for more details
  14.  *
  15.  */
  16.  
  17. #ifndef __CONTEXT_H
  18. #define __CONTEXT_H
  19.  
  20. #include "mgl/matrix.h"
  21. #include "mgl/config.h"
  22. #include "mgl/vertexbuffer.h"
  23.  
  24. #include <intuition/intuition.h>
  25.  
  26. #ifdef __PPC__
  27. #include <devices/timer.h>
  28.  
  29. typedef struct LockTimeHandle_s
  30. {
  31.     struct timeval StartTime;
  32. } LockTimeHandle;
  33. #else
  34. typedef struct LockTimeHandle_s
  35. {
  36.     ULONG s_hi, s_lo;
  37.     ULONG e_freq;
  38. } LockTimeHandle;
  39. #endif
  40.  
  41. struct GLcontext_t;
  42.  
  43. typedef void (*DrawFn)(struct GLcontext_t *);
  44.  
  45. typedef enum
  46. {
  47.     MGLKEY_F1, MGLKEY_F2, MGLKEY_F3, MGLKEY_F4, MGLKEY_F5, MGLKEY_F6, MGLKEY_F7, MGLKEY_F8,
  48.     MGLKEY_F9, MGLKEY_F10,
  49.     MGLKEY_CUP, MGLKEY_CDOWN, MGLKEY_CLEFT, MGLKEY_CRIGHT
  50. } MGLspecial;
  51.  
  52. typedef void (*KeyHandlerFn)(char key);
  53. typedef void (*SpecialHandlerFn)(MGLspecial special_key);
  54. typedef void (*MouseHandlerFn)(GLint x, GLint y, GLbitfield buttons);
  55. typedef void (*IdleFn)(void);
  56.  
  57. // NYI
  58. typedef struct
  59. {
  60.     int dummy;
  61. } MGLTextureFormat;
  62.  
  63. struct GLcontext_t
  64. {
  65.     /*
  66.     ** The primitive with which glBegin was called,
  67.     ** or GL_BASE if outside glBegin/glEnd
  68.     */
  69.  
  70.     GLenum      CurrentPrimitive;
  71.  
  72.     /*
  73.     ** Current error
  74.     */
  75.     GLenum      CurrentError;
  76.  
  77.     /*
  78.     ** The ModelView/Projection matrix stack.
  79.     ** Note that the topmost (= current) matrix is not the
  80.     ** top of the stack, but rather one of the ModelView[]/Projection[] below.
  81.     ** This makes copying the matrices unnecessary...
  82.     */
  83.     Matrix      ModelViewStack[MODELVIEW_STACK_SIZE];
  84.     int         ModelViewStackPointer;
  85.  
  86.     Matrix      ProjectionStack[PROJECTION_STACK_SIZE];
  87.     int         ProjectionStackPointer;
  88.  
  89.     /*
  90.     ** The current ModelView/Projeciton matrix.
  91.     ** The matrix multiplication routine will switch between those
  92.     ** two to avoid copying stuff.
  93.     */
  94.     Matrix      ModelView[2];
  95.     GLuint      ModelViewNr;
  96.  
  97.     #define     CurrentMV (&(context->ModelView[context->ModelViewNr]))
  98.     #define     SwitchMV  context->ModelViewNr = !(context->ModelViewNr)
  99.  
  100.     Matrix      Projection[2];
  101.     GLuint      ProjectionNr;
  102.  
  103.     #define     CurrentP (&(context->Projection[context->ProjectionNr]))
  104.     #define     SwitchP  context->ProjectionNr = !(context->ProjectionNr)
  105.  
  106.     // The current matrix mode (GL_MODELVIEW or GL_PROJECTION)
  107.     GLuint      CurrentMatrixMode;
  108.  
  109.  
  110.     /*
  111.     ** Vertex buffers
  112.     ** A call to glVertex*() will fill one entry of the vertex buffer
  113.     ** with the current data. glEnd() will go over this data and
  114.     ** draw the primitives based on this.
  115.     */
  116.     MGLVertex * VertexBuffer;
  117.     GLuint      VertexBufferSize;           // Size of the buffer
  118.     GLuint      VertexBufferPointer;        // Next free entry
  119.  
  120.     /*
  121.     ** Current colors and normals
  122.     */
  123.     GLuint      ClearColor;
  124.     W3D_Double  ClearDepth;
  125.     MGLColor    CurrentColor;
  126.     MGLNormal   CurrentNormal;
  127.     GLfloat     CurrentTexS, CurrentTexT;
  128.  
  129.     /*
  130.     ** The flag indicates wether the combined matrix is valid or not.
  131.     ** If it indicates GL_TRUE, the CombinedMatrix field contains the
  132.     ** product of the ModelView and Projection matrix.
  133.     */
  134.     GLboolean   CombinedValid;
  135.     Matrix      CombinedMatrix;
  136.  
  137.     /*
  138.     ** Scale factors for the transformation of normalized coordinates
  139.     ** to window coordinates. The *x and *y values are set by glViewPort.
  140.     ** *z is set by glDepthRange, which also sets near and far.
  141.     */
  142.     GLdouble    sx,sy,sz;
  143.     GLdouble    ax,ay,az;
  144.     GLdouble    near,far;
  145.  
  146.     // CullFace mode
  147.     GLenum      CurrentCullFace;
  148.     GLenum      CurrentFrontFace;
  149.  
  150.     // Pixel states
  151.     GLint       PackAlign;
  152.     GLint       UnpackAlign;
  153.  
  154.     /*
  155.     ** GL Rendering States
  156.     */
  157.     GLboolean   AlphaTest_State;
  158.     GLboolean   Blend_State;
  159.     GLboolean   Texture2D_State;
  160.     GLboolean   TextureGenS_State;
  161.     GLboolean   TextureGenT_State;
  162.     GLboolean   Fog_State;
  163.     GLboolean   Scissor_State;
  164.     GLboolean   CullFace_State;
  165.     GLboolean   DepthTest_State;
  166.     GLboolean   PointSmooth_State;
  167.     GLboolean   Dither_State;
  168.     GLboolean   ZOffset_State;
  169.  
  170.     /*
  171.     ** Drawing and clipping functions for the current primitive
  172.     */
  173.  
  174.     DrawFn      CurrentDraw;
  175.  
  176.     /*
  177.     ** Warp3D specific stuff
  178.     */
  179.  
  180.     W3D_Context *           w3dContext;
  181.     struct Window *         w3dWindow;
  182.     struct Screen *         w3dScreen;
  183.     W3D_Texture **          w3dTexBuffer;
  184.     GLubyte **              w3dTexMemory;
  185.     GLint                   TexBufferSize;
  186.     GLint                   CurrentBinding;
  187.     struct ScreenBuffer *   Buffers[3];
  188.     int                     BufNr;
  189.     int                     NumBuffers;
  190.     W3D_Scissor             scissor;
  191.     GLboolean               w3dLocked;
  192. #ifdef AUTOMATIC_LOCKING_ENABLE
  193.     GLenum                  LockMode;
  194.     LockTimeHandle          LockTime;
  195. #endif
  196.     GLboolean               DoSync;
  197.     ULONG            w3dChipID;
  198.     ULONG                   w3dFormat;
  199.     ULONG                   w3dAlphaFormat;
  200.     GLint                   w3dBytesPerTexel;
  201.  
  202.     GLenum                  TexEnv;
  203.     GLenum                  MinFilter;
  204.     GLenum                  MagFilter;
  205.     GLenum                  WrapS;
  206.     GLenum                  WrapT;
  207.  
  208.     W3D_Fog                 w3dFog;
  209.     ULONG                   w3dFogMode;
  210.     GLfloat                 FogRange;
  211.     GLfloat                 FogMult;
  212.     GLenum                  ShadeModel;
  213.     GLboolean               DepthMask;
  214.  
  215.     GLboolean               NoMipMapping;
  216.     GLboolean               NoFallbackAlpha;
  217.  
  218.     KeyHandlerFn            KeyHandler;
  219.     MouseHandlerFn          MouseHandler;
  220.     SpecialHandlerFn        SpecialHandler;
  221.     IdleFn                  Idle;
  222.     GLboolean               Running;
  223.  
  224.     GLenum              SrcAlpha;
  225.     GLenum              DstAlpha;
  226.     GLboolean               AlphaFellBack;
  227.  
  228.     GLfloat                 InvRot[9];
  229.     GLboolean        InvRotValid;
  230.  
  231.     GLboolean        WOne_Hint;
  232.  
  233.     GLfloat            ZOffset;
  234.  
  235.     // Registered texture format and converter routines
  236.     MGLTextureFormat    *Formats;
  237.     GLint            NumFormats;
  238. };
  239.  
  240. /*
  241. ** The CMATRIX macro give the address of the currently
  242. ** active matrix, depending on the matrix mode.
  243. ** The OMATRIX macro gives the address of the secondary matrix
  244. ** The SMATRIX macro switches the active and backup matrix
  245. */
  246. #define CMATRIX(context) context->CurrentMatrixMode == GL_MODELVIEW ?\
  247.     (&(context->ModelView[context->ModelViewNr])):\
  248.     (&(context->Projection[context->ProjectionNr]))
  249.  
  250. #define OMATRIX(context) context->CurrentMatrixMode == GL_MODELVIEW ?\
  251.     (&(context->ModelView[!(context->ModelViewNr)])):\
  252.     (&(context->Projection[!(context->ProjectionNr)]))
  253.  
  254. #define SMATRIX(context) if (context->CurrentMatrixMode == GL_MODELVIEW)\
  255.     context->ModelViewNr = !(context->ModelViewNr);\
  256.    else context->ProjectionNr = !(context->ProjectionNr)
  257.  
  258.  
  259. typedef struct GLcontext_t * GLcontext;
  260.  
  261. #endif
  262.  
  263.